package com.luoy.flow;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * 参数1：输入类型 k  文本数据的行号
 * 参数2：输入类型 v  文本数据的值
 */
public class FlowMapper extends Mapper<LongWritable, Text, Text, FlowBean>{
	FlowBean bean = new FlowBean();
	Text k = new Text();
	@Override
	protected void map(LongWritable key, Text value, Context context)
			throws IOException, InterruptedException {
		// 1.获取一行数据
		String line = value.toString();
		
		// 2.截取字段
		String[] fields = line.split("\t");

		String phoneNum = fields[1];
		// 3.封装bean对象以及获取电话号码
		long upFlow = Long.parseLong(fields[fields.length - 3]);
		long downFlow = Long.parseLong(fields[fields.length - 2]);
	
		bean.set(upFlow, downFlow);
		k.set(phoneNum);
		
		// 4.写出去
		context.write(k, bean);
	}
	
	
}
